package com.ak.server.quartz.service.impl;

import java.util.Date;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.ak.common.entity.QueryRequest;
import com.ak.common.entity.constant.Constants;
import com.ak.common.utils.SortUtil;
import com.ak.server.quartz.entity.SysJobLog;
import com.ak.server.quartz.mapper.SysJobLogMapper;
import com.ak.server.quartz.service.ISysJobLogService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

/**
 * 定时任务调度日志信息 服务层
 *
 * @author Vean
 */
@Service
@Transactional(propagation = Propagation.SUPPORTS, readOnly = true)
public class SysJobLogServiceImpl extends ServiceImpl<SysJobLogMapper, SysJobLog> implements ISysJobLogService {

    /**
     * 获取quartz调度器日志的计划任务
     *
     * @param jobLog 调度日志信息
     * @return 调度任务日志集合
     */
    @Override
    public IPage<SysJobLog> selectJobLogList(SysJobLog jobLog, QueryRequest request) {
        Page<SysJobLog> page = new Page<SysJobLog>(request.getPageNum(), request.getPageSize());
        SortUtil.handlePageSort(request, page, "create_time", Constants.ORDER_DESC, false);
        return this.baseMapper.findJobLogPage(page, jobLog);
    }

    /**
     * 新增任务日志
     *
     * @param jobLog 调度日志信息
     */
    @Override
    public void addJobLog(SysJobLog jobLog) {
    	jobLog.setCreateTime(new Date());
        this.baseMapper.insert(jobLog);
    }

    /**
     * 批量删除调度日志信息
     *
     * @param ids 需要删除的数据ID
     * @return 结果
     */
    @Override
    public int deleteJobLogByIds(String ids) {
        return baseMapper.deleteJobLogByIds(ids.split(","));
    }


    /**
     * 清空任务日志
     */
    @Override
    public void cleanJobLog() {
        baseMapper.cleanJobLog();
    }
}
